﻿Type=Activity
Version=5.8
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	
	
	Private btnselectall As Label
	Private btndel As Label
	Private bIsEditMode As Boolean=False,bIsSelectAll=False As Boolean
	Private popt As Panel
	Private ulvmyfavteacher As UltimateListView
	Private lstdata,lstChk As List
	Private bLoading=False,bScrolling=False As Boolean '下拉刷新用的
	
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'Do not forget to load the layout file created with the visual designer. For example:
	Activity.LoadLayout("laymyfavteacherlist")
	initviews
End Sub
Sub initviews
	Dim nh As Int=90dip
	ulvmyfavteacher.AddLayout("itemmyfavteacher","itemmyfavteacher_LayoutCreator","itemmyfavteacher_ContentFiller",nh,True)
	ulvmyfavteacher.AddLayout("itemrefush","itemmyfavteacher_LayoutCreator","itemmyfavteacher_ContentFiller",60dip,True)
	lstdata.Initialize
	lstChk.Initialize
	If g_store.conf.ContainsKey("favteclst") Then
		lstdata=g_store.conf.Get("favteclst")
		fillulv
	End If
	
	reqFav
End Sub
Private Sub fillulv
	ulvmyfavteacher.ClearContent
	For i=0 To lstdata.Size-1
		lstChk.Add(False)
		ulvmyfavteacher.AddItem("itemmyfavteacher",i)
	Next
	Log("fill_50")
	ulvmyfavteacher.RefreshContent
End Sub
Sub reqFav
	ProgressDialogShow("正在获取收藏的老师列表")
	ParseHelper.doGetReq(Me,"reqfav",comm.getApi(comm.apiIdx.MYFAVTEACHER),Null)
End Sub
Sub JobDone(thj As HttpJob)
	ProgressDialogHide
	If thj.Success Then
		Dim str As String=thj.GetString
		Dim nr As netRes=ParseHelper.getStatusData(str)
		Select thj.JobName
		Case "reqfav"
			If nr.nCode=200 Then
				lstdata=ParseHelper.parseFavTeacher(str)
				Log("got:"&lstdata.Size)
				g_store.conf.Put("favteclst",lstdata)
				fillulv
			Else
				comm.TL("获取收藏出错:"&nr.sData)
			End If
		Case "delfav"
			If nr.nCode=200 Then
				comm.TL("操作成功")
				g_store.conf.Put("favteclst",lstdata)
			Else
				comm.TL("操作失败:"&nr.sData)
			End If
		End Select
	Else
		comm.TL("reqFav:"&thj.ErrorMessage)
	End If
End Sub
'下拉刷新
Sub ulvmyfavteacher_Overscrolled(Action As Int, ScrollY As Int)
	'Log("A:"&Action&"  Y:"&ScrollY)
	Select Action
	Case 2'按下
		If bScrolling=False And ScrollY<-100 Then 
			ulvmyfavteacher.InsertItemAt("itemrefush",0,0)	
			bScrolling=True
		End If
	Case 1'放开
		If bScrolling Then
			bScrolling=False
			ulvmyfavteacher.RemoveItemAt(0)
			If ScrollY<-100 And bLoading=False Then '防止重复加载
				Log("req refush once")
				reqFav
			End If
		End If
	End Select
End Sub
Sub ulvmyfavteacher_EmptyView(LayoutPanel As Panel)
	LayoutPanel.LoadLayout("itemempty")
End Sub
Sub itemmyfavteacher_LayoutCreator(LayoutName As String, LayoutPanel As Panel)
	LayoutPanel.LoadLayout(LayoutName)
End Sub
Sub itemmyfavteacher_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
	If LayoutName.EqualsIgnoreCase("itemmyfavteacher") Then
		Log("filler_once pos:"&Position&" ID:"&ItemID)
	'	If lstdata.Size<1 Then
	'		ulvmyfavteacher.ClearContent
	'		Return '被清空了
	'	End If
	'	If Position>lstdata.Size-1 Then Return 
		Private itemchk As CheckBox
		Private itemteacheage As Label
		Private itemteacherdistence As Label
		Private itemteacherheaderriv As RIV
		Private itemteachernickname As Label
		Private itemteacherstatus As Label
		Private ivsex As ImageView
		Dim p As Panel=LayoutPanel.GetView(6)
		itemteacherheaderriv=p.GetView(0)
		itemchk=LayoutPanel.GetView(5)
		itemteachernickname=LayoutPanel.GetView(0)
		itemteacheage=LayoutPanel.GetView(2)
		itemteacherstatus=LayoutPanel.GetView(3)
		itemteacherdistence=LayoutPanel.GetView(4)
		Dim t As Teacher=lstdata.Get(ItemID)
		comm.loadimg(t.headimg,itemteacherheaderriv)
		itemteacherdistence.Text=t.distence
		itemteachernickname.Text=t.nickname
		itemteacherstatus.Text="评论数:"&t.rateNum&" 好评率:"&t.ratePercent&" 学生数:"&t.stunum
		itemteacheage.Text=t.teacheAge&"年教龄"
		itemchk.Checked=lstChk.Get(ItemID)
		itemchk.Visible=bIsEditMode
		itemchk.Tag=Position
	End If
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub ulvmyfavteacher_ItemClick(ItemID As Long, Position As Int, ClickedPanel As Panel)
	If bIsEditMode Then
		Dim p As Panel=ClickedPanel
		Dim cb As CheckBox=ClickedPanel.GetView(5)
		lstChk.Set(ItemID,Not(cb.Checked))
'		For Each v As View In p.GetAllViewsRecursive
'			If GetType(v).ToLowerCase.Contains("checkbox") Then
'				cb=v
'				cb.Checked=Not(cb.Checked)
'			End If
'		Next	
	Else
		'调用教师详情页面
		Dim t As Teacher=lstdata.Get(Position)
		Dim tecid As Int=t.id
		g_store.put("tecid",tecid)
		StartActivity(actTeacherDetail)
	End If
	Log("fill_148")
	ulvmyfavteacher.RefreshContent
End Sub

Sub clvmyfavteacher_ItemClick (Index As Int, Value As Object)
	
	
End Sub

Sub btnedit_Click
	bIsEditMode=Not(bIsEditMode)
'	swEditMode(bIsEditMode)
	popt.Visible=bIsEditMode
	Log("fill_161")
	ulvmyfavteacher.RefreshContent
End Sub

Private Sub doSelectAll(t As Boolean)
	For i=0 To lstChk.Size-1
		lstChk.Set(i,t)
	Next
	Log("fill_169")
	ulvmyfavteacher.RefreshContent
	
End Sub
Private Sub doDeleteSelected
	Dim delids As String
	Dim issel As Boolean
	Try
		Dim n As Int=lstdata.Size-1
		Dim tec As Teacher
		For i=lstdata.Size-1 To 0 Step -1
			If lstdata.Size=0 Or lstChk.Size=0	 Then
				ulvmyfavteacher.ClearContent
				Return
			End If			
			issel=lstChk.Get(i)
			If issel Then
				tec=lstdata.Get(i)
				delids=delids&tec.ID&","
				lstdata.RemoveAt(i)
				lstChk.RemoveAt(i)
				ulvmyfavteacher.RemoveItemAt(i) '一定要加上这句！！！！！
			End If
		Next
		If delids.Length>0 Then
			Log(delids)
			delids=delids.SubString2(0,delids.Length-1)
			ProgressDialogShow2("正在提交数据",False)
			ParseHelper.doGetReq(Me,"delfav",comm.getApi(comm.apiIdx.DELFAVTEACHER),Array As String("id",delids))
		End If
	Catch
		Log("dodelerr:"&LastException.Message)
	End Try
	
End Sub
Sub ivback_Click
	Activity.Finish
End Sub

Sub btnselectall_Click
	bIsSelectAll=Not(bIsSelectAll)
	doSelectAll(bIsSelectAll)
	If bIsSelectAll Then
		btnselectall.Text="不选"
	Else
		btnselectall.Text="全选"
	End If
End Sub

Sub btndel_Click
	doDeleteSelected
	btnedit_Click
End Sub

Sub itemchk_CheckedChange(Checked As Boolean)
	Dim chk As CheckBox=Sender
	lstChk.Set(chk.Tag,chk.Checked)
End Sub